//
//  JAFCalenderCollectionView.m
//  JAFDemo
//
//  Created by 阿飞 on 2018/1/24.
//  Copyright © 2018年 阿飞. All rights reserved.
//

#import "JAFCalenderCollectionView.h"
#import "JAFCalenderDayCollectionViewCell.h"
@interface JAFCalenderCollectionView()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic,strong)UICollectionView *collectionViewMonthAndDay;//日历或者月份
//@property(nonatomic,strong)UICollectionView *collectionViewYearAndMonth;//月份或者年份

@end

//获取屏幕 宽度、高度
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define RandColor RGBColor(arc4random_uniform(255), arc4random_uniform(255), arc4random_uniform(255))
@implementation JAFCalenderCollectionView
-(instancetype)initWithFrame:(CGRect)frame{//withTitle:(NSString *)dateMonth
    
    self = [super initWithFrame:frame];
    if (self) {
        for (int i=0; i<30; i++) {
            
            NSInteger  item = i+1;
            NSString *intemStr = [NSString stringWithFormat:@"%ld",item];
            [self.totalDaysArray addObject:intemStr];
            
        }
         [self collectionViewMonthAndDay];
       
       [self.collectionViewMonthAndDay reloadData];
     //   [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(refreshData) name:@"refreshData" object:nil];
        
    }
    return self;
}
-(NSMutableArray *)totalDaysArray{
    if (!_totalDaysArray) {
        _totalDaysArray = [[NSMutableArray alloc]init];
    }
    return _totalDaysArray;
}
-(void)refreshData{
    
    [self.collectionViewMonthAndDay reloadData];
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 30;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIndentifier = @"cell";
    JAFCalenderDayCollectionViewCell *cell = (JAFCalenderDayCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIndentifier forIndexPath:indexPath];
    
    if (!cell) {
        
        cell =[[JAFCalenderDayCollectionViewCell alloc]init];
        
    }
    
    //cell.model = self.monthdataA[indexPath.row];
    
    //cell.backgroundColor =[UIColor whiteColor];
    cell.label.text = @"1";
    int R = (arc4random() % 256) ;
    int G = (arc4random() % 256) ;
    int B = (arc4random() % 256) ;
    cell.backgroundColor = [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1];
    
    return cell;
}

//-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
//{
//
//    LXCalendarDayModel *model = self.monthdataA[indexPath.row];
//    model.isSelected = YES;
//
//    [self.monthdataA enumerateObjectsUsingBlock:^(LXCalendarDayModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
//
//        if (obj != model) {
//            obj.isSelected = NO;
//        }
//    }];
//
//    if (self.selectBlock) {
//        self.selectBlock(model.year, model.month, model.day);
//    }
//    [collectionView reloadData];
//
//}

-(UICollectionView *)collectionViewMonthAndDay{
    if (!_collectionViewMonthAndDay) {
        
        UICollectionViewFlowLayout *flow =[[UICollectionViewFlowLayout alloc]init];
        //325*403
        flow.minimumInteritemSpacing = 0;
        flow.minimumLineSpacing = 0;
        flow.sectionInset =UIEdgeInsetsMake(0, 0, 0, 0);
        
        flow.itemSize = CGSizeMake(SCREEN_WIDTH/6, 50);
        _collectionViewMonthAndDay =[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH, 5 * 50) collectionViewLayout:flow];
        _collectionViewMonthAndDay.delegate = self;
        _collectionViewMonthAndDay.dataSource = self;
        _collectionViewMonthAndDay.showsVerticalScrollIndicator = NO;
        _collectionViewMonthAndDay.showsHorizontalScrollIndicator = NO;
        _collectionViewMonthAndDay.scrollsToTop = YES;
       // _collectionViewMonthAndDay.backgroundColor = [UIColor whiteColor];
        [_collectionViewMonthAndDay registerClass:[JAFCalenderDayCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    }
    return _collectionViewMonthAndDay;
}
@end
